import { mxlistByParam } from "@/api/equipment/shape";
import { modelSelectList } from "@/api/data/backup";
import { locationAnalysisTree } from "@/api/equipment/position";
import { handleTree } from "@/utils/utils";

export const useModelList = () => {
	/** 模型列表 */
	const modelList = ref<any>([]);
	/** 获取全部模型列表 */
	const getModelList = async (params?: any, callback?: (data: any) => void) => {
		let obj = {
			pageNum: 1,
			pageSize: 1000
		};
		params = params || obj;
		const { rows } = await mxlistByParam(params);
		modelList.value = handleTree(rows, "modelCode", "upperModelCode");
		callback && callback(rows);
	};
	/** 获取备份模型列表 */
	const backModelList = async () => {
		const res = await modelSelectList();
		modelList.value = handleTree(res.data, "modelCode", "upperModelCode");
	};
	/** 获取模型分析列表 */
	const analysisModelList = async (callback?: (data: any) => void) => {
		const res = await locationAnalysisTree();
		modelList.value = handleTree(res.data, "modelCode", "upperModelCode");
		callback && callback(res.data);
	};
	return {
		modelList,
		getModelList,
		backModelList,
		analysisModelList
	};
};
